from goodDesignImage2018Spider.dao.waimaiyuan.fileInfoDao import *
from goodDesignImage2018Spider.util.file_operation import FileOperation
import time

waimaiyuan_cp_save_path = "/Volumes/files/waimaiyuan/caipu"

if __name__ == '__main__':
    while True:
        need_down_img = FileInfo.get_need_download_img()
        if len(need_down_img) < 1:
            print("下载结束")
            exit()

        for img in need_down_img:
            # 下载保存在本地
            file_path = FileOperation.down_img_by_file_info(img)

            if file_path is not None:
                img.file_relative_path = file_path.replace(waimaiyuan_cp_save_path, "")
                FileInfo.update_file_rel_path(img)
                print("下载完成:" + str(img.file_info_id))
            time.sleep(2)
